package com.jsyl.lwbk.web.controller.education;

import com.jsyl.lwbk.business.dto.education.AddQuestionReporttypeDTO;
import com.jsyl.lwbk.business.dto.education.QuestionReporttypeListDTO;
import com.jsyl.lwbk.business.service.education.IQuestionReporttypeService;
import com.jsyl.lwbk.business.vo.education.QuestionReportTypeVO;
import com.jsyl.lwbk.common.annotation.Log;
import com.jsyl.lwbk.common.core.controller.BaseController;
import com.jsyl.lwbk.common.core.domain.AjaxResult;
import com.jsyl.lwbk.common.core.page.TableDataInfo;
import com.jsyl.lwbk.common.enums.BusinessType;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author jh
 * @date 2021-04-02 16:27
 * @desc 训练项目报告类型
 **/
@Controller
@RequestMapping("/education/trainingProgramReporttype")
public class TrainingProgramReporttypeController extends BaseController {

    private String prefix = "education/trainingProgramReporttype";

    @Autowired
    private IQuestionReporttypeService questionReporttypeService;




    @RequiresPermissions("education:trainingProgramReporttype:view")
    @GetMapping()
    public String trainingProgramReporttype(ModelMap mmap) {
        return prefix + "/trainingProgramReporttype";
    }


    @GetMapping("/selectQuestion/{moduleId}")
    public String selectQuestion(@PathVariable("moduleId") Integer moduleId,ModelMap mmap) {
        mmap.put("moduleId", moduleId);
        return prefix + "/selectQuestion";
    }


    /**
     * 题目列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QuestionReporttypeListDTO questionReporttypeListDTO) {
        startPage();
        List<QuestionReportTypeVO> list = questionReporttypeService.findList(questionReporttypeListDTO);
        return getDataTable(list);
    }


    @PostMapping("/del")
    @Log(title = "项目报告类型", businessType = BusinessType.DELETE)
    @ResponseBody
    public AjaxResult trainingProgram(@RequestParam("questionId") Long questionId) {
        questionReporttypeService.deleteByQuestionId(questionId);
        return toAjax(Boolean.TRUE);
    }

    /**
     * 训练项目管理
     */
    @Log(title = "项目报告类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@Valid @RequestBody AddQuestionReporttypeDTO addQuestionReporttypeDTO) {
        questionReporttypeService.add(addQuestionReporttypeDTO);
        return toAjax(Boolean.TRUE);
    }


}
